<?php

use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;

class PermissionsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        foreach ($this->getPermissionsData() as $key => $value) {
            $permission = new Permission();
            $permission->name = $value['name'];
            $permission->description = $value['description'];
            $permission->group_name = $value['type'];
            $permissionExist = Permission::where('name',$value['name'])->first();
            if (!$permissionExist) {
                echo '添加新的一条新权限'.'....................'.$value['display_name'].PHP_EOL;
                $permission->save();
            }else{
                echo $value['display_name'].'....................该权限已经存在'.PHP_EOL;
            }

        }

    }

    protected function getPermissionsData()
    {
        $data = [
            // 权限管理
            [ 'name' => 'RoleController' , 'display_name' => '角色管理权限', 'type' => '权限管理','description' => '角色相关操作权限' ],
            [ 'name' => 'PermissionsController' , 'display_name' => '权限管理权限', 'type' => '权限管理','description' => '角色相关操作权限' ],

            //用户模块
            [ 'name' => 'UserController' , 'display_name' => '用户管理权限', 'type' => '用户管理','description' => '用户相关操作权限' ],

        ];

        return $data;
    }
}
